package cn.byapps.attendance.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.byapps.attendance.entity.Student;
import cn.byapps.attendance.service.StudentService;
import core.excel.ExportExcel;

/** excel */
@Controller
@RequestMapping("/excel")
public class ExcelController {

	@Resource
	StudentService studentService;

	/**
	 * 导出学生信息
	 * 
	 * @throws IOException
	 */
	@RequestMapping(value = "/exportStu")
	public String exportStu(Boolean b, HttpServletResponse response) throws IOException {
		List<Student> records = studentService.findAll();
		String fileName;
		if (b) {
			fileName = "student.xls";
		} else {
			fileName = "student.xlsx";
		}
		new ExportExcel(null, Student.class, b).setDataList(records).write(response, fileName).dispose();
		return null;
	}

}
